package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author stone
 * @date 2022/11/10 20:48
 */
public class LifeCycleBean implements BeanNameAware, BeanFactoryAware, ApplicationContextAware,
        InitializingBean, DisposableBean {

    String parameter;

    String beanName;

    BeanFactory beanFactory;

    ApplicationContext applicationContext;

    public LifeCycleBean() {
        System.out.println("Bean的实例化");
    }

    public void setParameter(String parameter) {
        System.out.println("设置属性值：" + parameter);
        this.parameter = parameter;
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("BeanNameAware接口的setBeanName方法：" + beanName);
        this.beanName = beanName;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("BeanFactoryAware的setBeanFactory方法");
        this.beanFactory = beanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("ApplicationContextAware的setApplicationContext方法");
        this.applicationContext = applicationContext;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet");
    }

    public void customInit() {
        System.out.println("自定义init");
    }
    public void customDestroy() {
        System.out.println("自定义customDestroy");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("DisposableBean接口提供的destroy");
    }

}
